package org.htmlparser.util;

import org.htmlparser.Node;
import org.htmlparser.Tag;
import org.htmlparser.lexer.Cursor;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.lexer.Page;
import org.htmlparser.scanners.Scanner;

public class IteratorImpl
  implements NodeIterator
{
  Cursor mCursor;
  ParserFeedback mFeedback;
  Lexer mLexer;

  public IteratorImpl(Lexer paramLexer, ParserFeedback paramParserFeedback)
  {
    this.mLexer = paramLexer;
    this.mFeedback = paramParserFeedback;
    this.mCursor = new Cursor(this.mLexer.getPage(), 0);
  }

  public boolean hasMoreNodes()
    throws ParserException
  {
    int i;
    this.mCursor.setPosition(this.mLexer.getPosition());
    if (65535 != this.mLexer.getPage().getCharacter(this.mCursor))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public Node nextNode()
    throws ParserException
  {
    Object localObject;
    try
    {
      localObject = this.mLexer.nextNode();
      if ((localObject != null) && (localObject instanceof Tag))
      {
        Tag localTag1 = (Tag)localObject;
        if (!(localTag1.isEndTag()))
        {
          Scanner localScanner = localTag1.getThisScanner();
          if (localScanner != null)
          {
            NodeList localNodeList = new NodeList();
            Tag localTag2 = localScanner.scan(localTag1, this.mLexer, localNodeList);
            localObject = localTag2;
          }
        }
      }
      return localObject;
    }
    catch (ParserException localParserException2)
    {
      throw localParserException2;
    }
    catch (Exception localException)
    {
      StringBuffer localStringBuffer = new StringBuffer();
      localStringBuffer.append("Unexpected Exception occurred while reading ");
      localStringBuffer.append(this.mLexer.getPage().getUrl());
      localStringBuffer.append(", in nextNode");
      ParserException localParserException1 = new ParserException(localStringBuffer.toString(), localException);
      this.mFeedback.error(localStringBuffer.toString(), localParserException1);
      throw localParserException1;
    }
  }
}